<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    "user strict";
    const user = { age: 18 };
    // 打印对象的相关属性，比如可读或者可写
    console.log(
      JSON.stringify(Object.getOwnPropertyDescriptor(user, "age"), null, 2)
    );
    // 如果有name属性那么就相当于修改，否则就相当于新增
    Object.defineProperty(user, "name", {
      value: "小灰",
      writable: false,
    });
    console.log(user);
    // 无法修改
    user.name = "小美";

    // 批量设置
    Object.defineProperties(user, {
      name: {
        value: "小美",
        writable: true,
        enumerable: false,
        configurable: true,
      },
      age: {
        value: "小美",
        // 能否修改属性的值
        writable: true,
        // 能否通过for-in循环返回属性
        enumerable: false,
// 能否通过delete删除属性从而重新定义属性
        configurable: true,
      }
    });
  </script>
</html>
